home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / misc / samples2 / cre8dir.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-24  |  2.1 KB  |  74 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5820
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1770
  7.    ClientWidth     =   7365
  8.    Height          =   6510
  9.    Left            =   1035
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5820
  12.    ScaleWidth      =   7365
  13.    Top             =   1140
  14.    Width           =   7485
  15.    Begin CommandButton Command1 
  16.       Caption         =   "Create Directory"
  17.       Height          =   495
  18.       Left            =   2505
  19.       TabIndex        =   0
  20.       Top             =   2685
  21.       Width           =   2055
  22.    End
  23.    Begin Menu mnuExit 
  24.       Caption         =   "Exit"
  25.    End
  26. Sub Command1_Click ()
  27.     'Specify the directory to create
  28.     DirName$ = "C:\VB\TEST1"
  29.     If Not DirExists(DirName$) Then
  30.         'Directory does not exist, so create it
  31.         I% = CreateDir(DirName$)
  32.         Select Case I%
  33.             Case True
  34.                 Msg$ = DirName$ + " successfully created."
  35.             Case False
  36.                 Msg$ = DirName$ + " not created due to error."
  37.         End Select
  38.     Else
  39.         'Directory exists
  40.         Msg$ = DirName$ + " already exists"
  41.     End If
  42.     MsgBox Msg$
  43. End Sub
  44. Function CreateDir (DirName$) As Integer
  45. 'This function will return TRUE if the directory passed
  46. 'to it was successfully created; FALSE if an error occurrs
  47.     On Error Resume Next
  48.     MkDir DirName$
  49.     If Err Then
  50.         CreateDir = False
  51.     Else
  52.         CreateDir = True
  53.     End If
  54. End Function
  55. Function DirExists (DirName$) As Integer
  56. 'This function will return TRUE if the directory passed
  57. 'to it exists; FALSE if it doesn't or a runtime error
  58. 'occurs
  59.     Const ATTR_DIRECTORY = 16
  60.     Const ATTR_HIDDEN = 2
  61. On Error Resume Next
  62.     If Len(Dir$(DirName$, ATTR_DIRECTORY + ATTR_HIDDEN)) = 0 Then
  63.         DirExists = False
  64.     Else
  65.         DirExists = True
  66.     End If
  67. End Function
  68. Sub Form_Unload (Cancel As Integer)
  69.     End
  70. End Sub
  71. Sub mnuExit_Click ()
  72.     Unload Me
  73. End Sub
  74.